<template>
    <Modal
        :value="value"
        title="添加班级"
        @input="handleInput"
    >
        <ClassTable
            :data="list"
            :type="1"
            @on-selection-change="selectChange"
        />
        <div slot="footer">
            <Button
                @click="handleInput(false)"
            >取消</Button>
            <Button
                type="primary"
                @click="submit"
            >确定</Button>
        </div>
    </Modal>
</template>
<script>
import { queryClassList } from '@/api/classManage'
import ClassTable from './ClassTable'

export default {
    props: {
        value: {
            type: Boolean,
            default: false
        }
    },
    components: {
        ClassTable
    },
    data () {
        return {
            params: {
                className: '',
                total: 0,
                pageNum: 1,
                pageSize: 10000
            },
            list: []
        }
    },
    mounted () {
        this.queryClassList()
    },
    methods: {
        handleInput (v) {
            this.$emit('input', v)
        },
        queryClassList () {
            queryClassList(this.params).then(res => {
                if (res.data.code === '0000') {
                    this.list = res.data.data.list
                    this.params.total = res.data.data.total
                }
            })
        },
        selectChange (v) {
            this._selected = v
        },
        submit () {
            this.$emit('on-ok', this._selected || [])
            this.handleInput(false)
        }
    }
}
</script>
